package com.zn.services.impl;

import com.zn.common.constants.Constants;
import com.zn.common.exception.MyException;
import com.zn.common.resp.ApiResult;
import com.zn.common.utils.FileUtils;
import com.zn.common.utils.QrCodeUtils;
import com.zn.dao.ReportVerifyInfo2Mapper;
import com.zn.dao.ReportVerifyInfoMapper;
import com.zn.dao.VeiReportInfo2Mapper;
import com.zn.dao.VeiReportInfoMapper;
import com.zn.dto.CheckReportDTO;
import com.zn.dto.VeiReportInfoDTO;
import com.zn.dto.VeiReportInfoDTO2;
import com.zn.pojo.*;
import com.zn.pojo.android.VehicleImage;
import com.zn.services.VeiReportInfoService;
import lombok.extern.log4j.Log4j2;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Date;
import java.util.List;

@Log4j2
@Service
public class VeiReportInfoServiceImpl implements VeiReportInfoService {
    @Autowired
    private VeiReportInfoMapper veiReportInfoMapper;
    @Autowired
    private VeiReportInfo2Mapper veiReportInfo2Mapper;
    @Autowired
    private ReportVerifyInfoMapper reportVerifyInfoMapper;
    @Autowired
    private ReportVerifyInfo2Mapper reportVerifyInfo2Mapper;


    @Transactional
    @Override
    public int addVeiReportInfo(Integer type, VeiReportInfo info, Integer uid) {
        log.info("-----------插入数据中--------");
        int count1 = 0;
        int count2 = 0;
        try {
            count1 = veiReportInfoMapper.insertSelective(info);
            if (count1 == 0) {
                throw new MyException(500, "操作失败!请及时联系管理员!");
            }
            ReportVerifyInfo report = new ReportVerifyInfo();
            report.setReportId(info.getReportId());
            report.setUserId(uid);
            if (type == null) {
                report.setStatus(Constants.REPORT_STATUS1);
            } else if (type == 0) {
                report.setStatus(Constants.REPORT_STATUS0);
            } else if (type == 1) {
                report.setStatus(Constants.REPORT_STATUS1);
            }
            count2 = reportVerifyInfoMapper.insertSelective(report);
            if (count2 == 0) {
                throw new MyException(500, "操作失败!请及时联系管理员!");
            }
            log.info("-----------操作数据完毕---->数据:" + count1 + "条--------");
        } catch (Exception e) {
            log.error("插入检测报告:" + e);
            e.printStackTrace();
            throw new MyException(500, "操作失败!请及时联系管理员!");
        }
        return count1;
    }


    @Override
    public int saveVeiReportInfo(VeiReportInfo info, Integer uid) {
        return veiReportInfoMapper.updateByPrimaryKeySelective(info);
    }

    @Override
    @Transactional
    public int removeReport1(Integer rid, Integer uid) {
        try {
            reportVerifyInfoMapper.deleteByRid(rid);
            veiReportInfoMapper.deleteByPrimaryKey(rid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    @Override
    public List<VeiReportInfoDTO2> getUserReport2ByUid(Integer uid) {
        List<VeiReportInfoDTO2> list = veiReportInfo2Mapper.selectByUid(uid);
        return list;
    }

    @Override
    public int addReport1PrintCount(Integer rid) {
        return reportVerifyInfoMapper.updatePrintCountByRid(rid);
    }

    @Override
    @Transactional
    public int removeReport2(Integer rid, Integer uid) {
        try {
            reportVerifyInfo2Mapper.deleteByRid(rid);
            veiReportInfo2Mapper.deleteByPrimaryKey(rid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    @Override
    public List<VeiReportInfoDTO> getReportByHid(Integer status, Integer hid) {
        return veiReportInfoMapper.selectByHid(status, hid);
    }

    @Override
    public VeiReportInfo2 getReport2ByRid(Integer rid) {
        return veiReportInfo2Mapper.selectByPrimaryKey(rid);
    }

    @Override
    public VeiReportInfo2 getVeiReportInfo2ByRid(Integer rid) {
        return veiReportInfo2Mapper.selectByPrimaryKey(rid);
    }

    @Override
    public List<VeiReportInfoDTO2> getAllUserReport2ByStatus(Integer status) {
        return veiReportInfo2Mapper.selectReportByStatus(status);
    }

    @Override
    public List<VeiReportInfoDTO2> getReport2ByHid(Integer status, Integer hid) {
        return veiReportInfo2Mapper.selectByHid(status, hid);
    }

    @Override
    public int modifyReportInfo2(VeiReportInfo2 info) {
        return veiReportInfo2Mapper.updateByPrimaryKeySelective(info);
    }

    @Override
    public List<VeiReportInfoDTO2> getUserReport2ByStatus(Integer uid, Integer status) {
        return veiReportInfo2Mapper.selectReportByUidAndStatus(uid, status);
    }

    @Override
    public int modifyReport2Status(Integer rid, Integer status) {
        ReportVerifyInfo info = new ReportVerifyInfo();
        info.setStatus(status);
        info.setReportId(rid);
        return reportVerifyInfo2Mapper.updateStatusByRid(info);
    }

    @Override
    public boolean checkReportNumberRepetition(String reportNumber) {
        List<VeiReportInfo> info = null;
        try {
            info = veiReportInfoMapper.selectByReportNumber(reportNumber);
        } catch (Exception e) {
        }
        if (null == info) {
            return false;
        } else if (info.size() >= 1) {
            return true;
        }
        return false;
    }

    @Override
    public VeiReportInfo2 getUserReport2ByRid(Integer rid) {
        return veiReportInfo2Mapper.selectByPrimaryKey(rid);
    }

    @Override
    public boolean verifyReport2(CheckReportDTO info) {
        ReportVerifyInfo2 verifyInfo = new ReportVerifyInfo2();
        verifyInfo.setVerifyId(info.getVerifyId());
        verifyInfo.setVerifyAdminid(info.getAdminId());
        verifyInfo.setVerifyReason(info.getMessage());
        verifyInfo.setStatus(info.getStatus());
        verifyInfo.setVerifyTime(new Date());
        int i = reportVerifyInfo2Mapper.updateByPrimaryKeySelective(verifyInfo);
        if (i == 1) {
            return true;
        }
        return false;
    }

    @Override
    public boolean auditReport2(CheckReportDTO info) {
        ReportVerifyInfo2 verifyInfo = new ReportVerifyInfo2();
        verifyInfo.setVerifyId(info.getVerifyId());
        verifyInfo.setAuditAdminid(info.getAdminId());
        verifyInfo.setAuditReason(info.getMessage());
        verifyInfo.setStatus(info.getStatus());
        verifyInfo.setAuditTime(new Date());
        int i = reportVerifyInfo2Mapper.updateByPrimaryKeySelective(verifyInfo);
        if (i == 1) {
            return true;
        }
        return false;
    }

    @Override
    public String getReport2ErrorInfo(Integer rid, Integer status) {
        String errorMsg = "";
        if (status == Constants.REPORT_STATUS3) {
            errorMsg = reportVerifyInfo2Mapper.selectVerifyReasonInfo(rid);
        } else if (status == Constants.REPORT_STATUS5) {
            errorMsg = reportVerifyInfo2Mapper.selectAuditReasonInfo(rid);
        }
        return errorMsg;
    }

    @Override
    public int addReport2PrintCount(Integer rid) {
        return reportVerifyInfo2Mapper.updatePrintCountByRid(rid);
    }


    @Override
    public int addVeiReport2Info(VeiReportInfo2 info, Integer uid, Integer status) {
        log.info("-----------插入数据中--------");
        int count1 = 0;
        int count2 = 0;
        try {
            count1 = veiReportInfo2Mapper.insertSelective(info);
            if (count1 == 0) {
                throw new MyException(500, "上传失败!请及时联系管理员!");
            }
            ReportVerifyInfo2 report = new ReportVerifyInfo2();
            report.setReportId(info.getReport2Id());
            report.setUserId(uid);
            report.setStatus(status);
            count2 = reportVerifyInfo2Mapper.insertSelective(report);
            if (count2 == 0) {
                throw new MyException(500, "上传失败!请及时联系管理员!");
            }
            log.info("-----------插入数据完毕---->数据:" + count1 + "条--------");
        } catch (Exception e) {
            log.error("上传检测报告:" + e);
            e.printStackTrace();
            throw new MyException(500, "上传失败!请及时联系管理员!");
        }
        return count1;
    }


    @Override
    public List<VeiReportInfo> getAllVeiReportInfo() {
        return null;
//        return veiReportInfoMapper.selectAllReportInfo();
    }

    @Override
    public VeiReportInfo getVeiReportInfoByRid(Integer rid) {
        return veiReportInfoMapper.selectByPrimaryKey(rid);
    }

    @Override
    public List<VeiReportInfoDTO> getUserReportByUid(Integer uid) {
        return veiReportInfoMapper.selectReportByUid(uid);
    }

    @Override
    public List<VeiReportInfoDTO> getUserReportByStatus(Integer uid, Integer status) {
        return veiReportInfoMapper.getUserReportByStatus(uid, status);
    }

    @Override
    public VeiReportInfo getUserReportByRid(Integer rid) {
        return veiReportInfoMapper.selectByPrimaryKey(rid);
    }

    @Override
    public boolean verifyReport(CheckReportDTO info) {
        ReportVerifyInfo verifyInfo = new ReportVerifyInfo();
        verifyInfo.setVerifyId(info.getVerifyId());
        verifyInfo.setVerifyAdminid(info.getAdminId());
        verifyInfo.setVerifyReason(info.getMessage());
        verifyInfo.setStatus(info.getStatus());
        verifyInfo.setVerifyTime(new Date());
        int i = reportVerifyInfoMapper.updateByPrimaryKeySelective(verifyInfo);
        if (i == 1) {
            return true;
        }
        return false;
    }

    @Override
    public boolean auditReport(CheckReportDTO info) {
        ReportVerifyInfo verifyInfo = new ReportVerifyInfo();
        verifyInfo.setVerifyId(info.getVerifyId());
        verifyInfo.setAuditAdminid(info.getAdminId());
        verifyInfo.setAuditReason(info.getMessage());
        verifyInfo.setStatus(info.getStatus());
        verifyInfo.setAuditTime(new Date());
        int i = reportVerifyInfoMapper.updateByPrimaryKeySelective(verifyInfo);
        if (i == 1) {
            return true;
        }
        return false;
    }

    @Override
    public List<VeiReportInfoDTO> getAllUserReport() {
        return veiReportInfoMapper.selectAllReport();
    }

    @Override
    public List<VeiReportInfoDTO> getAllUserReportByStatus(Integer status) {
        return veiReportInfoMapper.selectReportByStatus(status);
    }

    @Override
    public int modifyReportByRid(VeiReportInfo info) {
        return veiReportInfoMapper.updateByPrimaryKeySelective(info);
    }

    @Override
    public int getStatusByRidAndUid(Integer reportId, Integer uid) {
        return reportVerifyInfoMapper.selectStatusByRidAndUid(reportId, uid);
    }

    @Override
    public int modifyReportStatus(Integer reportId, Integer uid, int status) {
        ReportVerifyInfo info = new ReportVerifyInfo();
        info.setStatus(status);
        info.setReportId(reportId);
        info.setUserId(uid);
        return reportVerifyInfoMapper.updateStatusByRidAndUid(info);
    }

    @Override
    @Transactional
    public ApiResult modifyReportInfo(Integer role, Integer uid, VeiReportInfo info) {
        try {
            if (role == Constants.ROLE_ORDINARY_USER) {   //普通用户要修改 , 先判断是不是 审核通过 , 批准通过 , 如果已通过 , 不可修改
                int status = this.getStatusByRidAndUid(info.getReportId(), uid);
                if (status == -1) {
                    return new ApiResult(500, "修改失败!");
                } else if (status == Constants.REPORT_STATUS2) {
                    return new ApiResult(500, "------已审核通过-----不可修改!");
                } else if (status == Constants.REPORT_STATUS4) {
                    return new ApiResult(500, "------已批准通过-----不可修改!");
                } else if (status == Constants.REPORT_STATUS6) {
                    return new ApiResult(500, "------已归档-----不可修改!");
                } else if (status == Constants.REPORT_STATUS3 || status == Constants.REPORT_STATUS5) {  //用户在"未"审批 或者 "未"批准通过时 , 将修改其状态为 待审核.
                    int temp = this.modifyReportStatus(info.getReportId(), uid, Constants.REPORT_STATUS1);
                    //todo 并清除 时间 , 驳回缘由 , 根据现有逻辑可不处理 , 但最好弄一下 , 在mybatis里面进行动态sql处理
                    if (temp != 1) {
                        throw new MyException(500, "");
                    }
                }
            }
            int count = this.modifyReportByRid(info);
            if (count == 1) {
                return new ApiResult(200, "请求成功!");
            } else {
                throw new MyException(500, "");
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException(500, "操作失败!");
        }
    }

    @Override
    public ApiResult modifyReport2Info(Integer role, Integer uid, VeiReportInfo2 info) {
        try {
            if (role == Constants.ROLE_ORDINARY_USER) {   //普通用户要修改 , 先判断是不是 审核通过 , 批准通过 , 如果已通过 , 不可修改
                int status = this.getStatusByRid2(info.getReport2Id());
                if (status == -1) {
                    return new ApiResult(500, "修改失败!");
                } else if (status == Constants.REPORT_STATUS2) {
                    return new ApiResult(500, "------已审核通过-----不可修改!");
                } else if (status == Constants.REPORT_STATUS4) {
                    return new ApiResult(500, "------已批准通过-----不可修改!");
                } else if (status == Constants.REPORT_STATUS6) {
                    return new ApiResult(500, "------已归档-----不可修改!");
                } else if (status == Constants.REPORT_STATUS3 || status == Constants.REPORT_STATUS5) {  //用户在"未"审批 或者 "未"批准通过时 , 将修改其状态为 待审核.
                    int temp = this.modifyReport2Status(info.getReport2Id(), Constants.REPORT_STATUS1);
                    //todo 并清除 时间 , 驳回缘由 , 根据现有逻辑可不处理 , 但最好弄一下 , 在mybatis里面进行动态sql处理
                    if (temp != 1) {
                        throw new MyException(500, "");
                    }
                }
            }
            int count = this.modifyReport2ByRid(info);
            if (count == 1) {
                return new ApiResult(200, "请求成功!");
            } else {
                throw new MyException(500, "操作失败!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException(500, "操作失败!");
        }
    }

    private int getStatusByRid2(Integer rid) {
        return reportVerifyInfo2Mapper.selectStatusByRid(rid);
    }

    private int modifyReport2ByRid(VeiReportInfo2 info) {
        return veiReportInfo2Mapper.updateByPrimaryKeySelective(info);
    }

    @Override
    public String getReportErrorInfo(Integer rid, Integer status) {

        String errorMsg = "";
        if (status == Constants.REPORT_STATUS3) {
            errorMsg = reportVerifyInfoMapper.selectVerifyReasonInfo(rid);
        } else if (status == Constants.REPORT_STATUS5) {
            errorMsg = reportVerifyInfoMapper.selectAuditReasonInfo(rid);
        }
        return errorMsg;
    }

    @Override
    public XSSFWorkbook exportTsReport2Excel(VeiReportInfo2 info2) {
        XSSFWorkbook wb = null;
        try {
            wb = new XSSFWorkbook(new FileInputStream(Constants.TS_REPORT2_MODAL_URL));
        } catch (IOException e) {
            e.printStackTrace();
        }
        XSSFSheet sheet = wb.getSheetAt(0);
        sheet.getRow(1).getCell(2).setCellValue(info2.getReportNumber());
        sheet.getRow(9).getCell(15).setCellValue(info2.getReportNumber());
        sheet.getRow(29).getCell(2).setCellValue(info2.getReportNumber());
        sheet.getRow(56).getCell(2).setCellValue(info2.getReportNumber());
        sheet.getRow(84).getCell(2).setCellValue(info2.getReportNumber());

        sheet.getRow(14).getCell(10).setCellValue(info2.getProjectName());
        sheet.getRow(15).getCell(10).setCellValue(info2.getEntrustingParty());
        sheet.getRow(16).getCell(10).setCellValue(info2.getCheckCategory());
        sheet.getRow(17).getCell(10).setCellValue(info2.getReportDate());

        String sb = "    " + "被检单位位于" + info2.getCheckAddress() + "受" + info2.getEntrustingParty() +
                "委托，" + "我公司于" + info2.getCheckDate() + "对该单位指定的非道路柴油移动机械排气烟度进行了检测，现已完成检测报告。";
        sheet.getRow(32).getCell(2).setCellValue(sb);

        sheet.getRow(37).getCell(24).setCellValue(info2.getCheckMethod());
        sheet.getRow(41).getCell(2).setCellValue(info2.getEquipmentName());
        sheet.getRow(41).getCell(10).setCellValue(info2.getEquipmentModel());
        sheet.getRow(41).getCell(23).setCellValue(info2.getEquipmentMeasurementCertificate());
        sheet.getRow(44).getCell(8).setCellValue(info2.getMachineName());
        sheet.getRow(44).getCell(23).setCellValue(info2.getMachineModel());
        sheet.getRow(45).getCell(8).setCellValue(info2.getSerialNumber());
        sheet.getRow(45).getCell(23).setCellValue(info2.getHbNumber());
        sheet.getRow(46).getCell(8).setCellValue(info2.getMachineProtectionNumber());
        sheet.getRow(46).getCell(23).setCellValue(info2.getEquipmentNumber());
        sheet.getRow(47).getCell(8).setCellValue(info2.getEmissionPeriod());
        sheet.getRow(47).getCell(23).setCellValue(info2.getMachineDate());
        sheet.getRow(48).getCell(8).setCellValue(info2.getMachineVin());
        sheet.getRow(48).getCell(23).setCellValue(info2.getMachineManufacturer());
        sheet.getRow(49).getCell(8).setCellValue(info2.getEngineModel());
        sheet.getRow(49).getCell(23).setCellValue(info2.getEngineNumber());
        sheet.getRow(50).getCell(8).setCellValue(info2.getEngineManufacturer());
        sheet.getRow(50).getCell(23).setCellValue(info2.getEngineReprocessType());
        sheet.getRow(51).getCell(8).setCellValue(info2.getEngineSpeed());
        sheet.getRow(51).getCell(23).setCellValue(info2.getEnginePower());
        sheet.getRow(52).getCell(8).setCellValue(info2.getEnviProtNo());
        sheet.getRow(52).getCell(23).setCellValue(info2.getEngineApprovalNumber());
        sheet.getRow(59).getCell(8).setCellValue(info2.getAgentName());
        sheet.getRow(60).getCell(8).setCellValue(info2.getAgentMobile());
        sheet.getRow(61).getCell(8).setCellValue(info2.getAgentAddress());
        sheet.getRow(64).getCell(6).setCellValue(info2.getTemperature());
        sheet.getRow(64).getCell(14).setCellValue(info2.getPressure());
        sheet.getRow(64).getCell(21).setCellValue(info2.getHumidity());
        sheet.getRow(64).getCell(28).setCellValue(info2.getElevation());
        sheet.getRow(68).getCell(9).setCellValue(info2.getCheckDate());
        sheet.getRow(68).getCell(24).setCellValue(info2.getCheckStartEndTime());
        sheet.getRow(70).getCell(11).setCellValue(info2.getCheckAvg());
        sheet.getRow(70).getCell(16).setCellValue(info2.getCheckSpeed());
        sheet.getRow(70).getCell(21).setCellValue(info2.getCheckHighArea());
        sheet.getRow(70).getCell(26).setCellValue(info2.getCheckLimit());
        sheet.getRow(71).getCell(2).setCellValue(info2.getCheckResult1());
        sheet.getRow(71).getCell(5).setCellValue(info2.getCheckResult2());
        sheet.getRow(71).getCell(8).setCellValue(info2.getCheckResult3());
        sheet.getRow(72).getCell(11).setCellValue(info2.getCheckVp());
        sheet.getRow(74).getCell(11).setCellValue(info2.getCheckJudgment());

        try {
            //有时候 签发后 无法生成二维码 , 就再次验证是否有此 二维码 , 如果没就再生成一次
            if (!FileUtils.isExist(Constants.QRCODE_IMG_LOCAL_URL2 + info2.getReportNumber() + ".jpg")) {
                String qrCodeUrl = Constants.QRCODE_REPORT_URL2 + info2.getReport2Id() + "&" + "token=" + info2.getReportNumber().substring(6);
                QrCodeUtils.encode(qrCodeUrl, "", Constants.QRCODE_IMG_LOCAL_URL2, info2.getReportNumber() + ".png", false);
            }
            insertPicCost(wb, sheet, Constants.QRCODE_IMG_LOCAL_URL2 + info2.getReportNumber() + ".jpg", 26, 9, 30, 11);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 3 87 15 97     ->  18  87  30 97
        // 3 99 15 109     ->  18  99  30 109
        // 3 111 15 121     ->  18  111  30 121
        // 3 123 15 133     ->  18  123  30 133
        insertPicCost(wb, sheet, info2.getPic1(), 3, 87, 15, 97);
        insertPicCost(wb, sheet, info2.getPic2(), 18, 87, 30, 97);
        insertPicCost(wb, sheet, info2.getPic3(), 3, 99, 15, 109);
        insertPicCost(wb, sheet, info2.getPic4(), 18, 99, 30, 109);
        insertPicCost(wb, sheet, info2.getPic5(), 3, 111, 15, 121);
        insertPicCost(wb, sheet, info2.getPic6(), 18, 111, 30, 121);
        insertPicCost(wb, sheet, info2.getPic7(), 3, 123, 15, 133);
        insertPicCost(wb, sheet, info2.getPic8(), 18, 123, 30, 133);

        return wb;
    }

    @Override
    public XSSFWorkbook exportReport2Excel(VeiReportInfo2 info2) {
        XSSFWorkbook wb = null;
        try {
            if (info2.getReportNumber().contains("ZNHEDA") || info2.getReportNumber().equals("ZNHEBA")) {
                wb = new XSSFWorkbook(new FileInputStream(Constants.CZ_REPORT2_MODAL_URL));
            } else {
                wb = new XSSFWorkbook(new FileInputStream(Constants.REPORT2_MODAL_URL));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        XSSFSheet sheet = wb.getSheetAt(0);
        sheet.getRow(1).getCell(2).setCellValue(info2.getReportNumber());
        sheet.getRow(9).getCell(15).setCellValue(info2.getReportNumber());
        sheet.getRow(31).getCell(2).setCellValue(info2.getReportNumber());
        sheet.getRow(51).getCell(2).setCellValue(info2.getReportNumber());
        sheet.getRow(78).getCell(2).setCellValue(info2.getReportNumber());
        sheet.getRow(106).getCell(2).setCellValue(info2.getReportNumber());
        sheet.getRow(16).getCell(10).setCellValue(info2.getProjectName());
        sheet.getRow(17).getCell(10).setCellValue(info2.getEntrustingParty());
        sheet.getRow(18).getCell(10).setCellValue(info2.getCheckCategory());
        sheet.getRow(19).getCell(10).setCellValue(info2.getReportDate());
        StringBuffer sb = new StringBuffer();
        sb.append("    ").append("被检单位位于").append(info2.getCheckAddress()).append("受").append(info2.getEntrustingParty())
                .append("委托，").append("我公司于").append(info2.getCheckDate()).append("对该单位指定的非道路柴油移动机械排气烟度进行了检测，现已完成检测报告。");
        sheet.getRow(54).getCell(2).setCellValue(sb.toString());
//        sheet.getRow(59).getCell(2).setCellValue(info2.getCheckMethod());
//        sheet.getRow(59).getCell(7).setCellValue("方法名称");
//        sheet.getRow(59).getCell(18).setCellValue("方法编号");
        sheet.getRow(59).getCell(24).setCellValue(info2.getCheckMethod());
        sheet.getRow(63).getCell(2).setCellValue(info2.getEquipmentName());
        sheet.getRow(63).getCell(10).setCellValue(info2.getEquipmentModel());
        sheet.getRow(63).getCell(23).setCellValue(info2.getEquipmentMeasurementCertificate());
        sheet.getRow(66).getCell(8).setCellValue(info2.getMachineName());
        sheet.getRow(66).getCell(23).setCellValue(info2.getMachineModel());
        sheet.getRow(67).getCell(8).setCellValue(info2.getSerialNumber());
        sheet.getRow(67).getCell(23).setCellValue(info2.getHbNumber());
        sheet.getRow(68).getCell(8).setCellValue(info2.getMachineProtectionNumber());
        sheet.getRow(68).getCell(23).setCellValue(info2.getEquipmentNumber());
        sheet.getRow(69).getCell(8).setCellValue(info2.getEmissionPeriod());
        sheet.getRow(69).getCell(23).setCellValue(info2.getMachineDate());
        sheet.getRow(70).getCell(8).setCellValue(info2.getMachineVin());
        sheet.getRow(70).getCell(23).setCellValue(info2.getMachineManufacturer());
        sheet.getRow(71).getCell(8).setCellValue(info2.getEngineModel());
        sheet.getRow(71).getCell(23).setCellValue(info2.getEngineNumber());
        sheet.getRow(72).getCell(8).setCellValue(info2.getEngineManufacturer());
        sheet.getRow(72).getCell(23).setCellValue(info2.getEngineReprocessType());
        sheet.getRow(73).getCell(8).setCellValue(info2.getEngineSpeed());
        sheet.getRow(73).getCell(23).setCellValue(info2.getEnginePower());
        sheet.getRow(74).getCell(8).setCellValue(info2.getEnviProtNo());
        sheet.getRow(74).getCell(23).setCellValue(info2.getEngineApprovalNumber());
        sheet.getRow(81).getCell(8).setCellValue(info2.getAgentName());
        sheet.getRow(82).getCell(8).setCellValue(info2.getAgentMobile());
        sheet.getRow(83).getCell(8).setCellValue(info2.getAgentAddress());
        sheet.getRow(86).getCell(6).setCellValue(info2.getTemperature());
        sheet.getRow(86).getCell(14).setCellValue(info2.getPressure());
        sheet.getRow(86).getCell(21).setCellValue(info2.getHumidity());
        sheet.getRow(86).getCell(28).setCellValue(info2.getElevation());
        sheet.getRow(90).getCell(9).setCellValue(info2.getCheckDate());
        sheet.getRow(90).getCell(24).setCellValue(info2.getCheckStartEndTime());
        sheet.getRow(92).getCell(11).setCellValue(info2.getCheckAvg());
        sheet.getRow(92).getCell(16).setCellValue(info2.getCheckSpeed());
        sheet.getRow(92).getCell(21).setCellValue(info2.getCheckHighArea());
        sheet.getRow(92).getCell(26).setCellValue(info2.getCheckLimit());
        sheet.getRow(93).getCell(2).setCellValue(info2.getCheckResult1());
        sheet.getRow(93).getCell(5).setCellValue(info2.getCheckResult2());
        sheet.getRow(93).getCell(8).setCellValue(info2.getCheckResult3());
        sheet.getRow(94).getCell(11).setCellValue(info2.getCheckVp());
        sheet.getRow(96).getCell(11).setCellValue(info2.getCheckJudgment());
//        9  26   11 30
        try {
            //有时候 签发后 无法生成二维码 , 就再次验证是否有此 二维码 , 如果没就再生成一次
            if (!FileUtils.isExist(Constants.QRCODE_IMG_LOCAL_URL2 + info2.getReportNumber() + ".jpg")) {
                String qrCodeUrl = Constants.QRCODE_REPORT_URL2 + info2.getReport2Id() + "&" + "token=" + info2.getReportNumber().substring(6);
                QrCodeUtils.encode(qrCodeUrl, "", Constants.QRCODE_IMG_LOCAL_URL2, info2.getReportNumber() + ".png", false);
            }
            insertPicCost(wb, sheet, Constants.QRCODE_IMG_LOCAL_URL2 + info2.getReportNumber() + ".jpg", 26, 9, 30, 11);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 3 109 15 119     ->  18  109  30 119
        // 3 121 15 131     ->  18  121  30 131
        // 3 133 15 143     ->  18  133  30 143
        // 3 145 15 155     ->  18  145  30 155
        // 3 157 15 167     ->  18  157  30 167
        insertPicCost(wb, sheet, info2.getPic1(), 3, 109, 15, 119);
        insertPicCost(wb, sheet, info2.getPic2(), 18, 109, 30, 119);
        insertPicCost(wb, sheet, info2.getPic3(), 3, 121, 15, 131);
        insertPicCost(wb, sheet, info2.getPic4(), 18, 121, 30, 131);
        insertPicCost(wb, sheet, info2.getPic5(), 3, 133, 15, 143);
        insertPicCost(wb, sheet, info2.getPic6(), 18, 133, 30, 143);
        insertPicCost(wb, sheet, info2.getPic7(), 3, 145, 15, 155);
        insertPicCost(wb, sheet, info2.getPic8(), 18, 145, 30, 155);
        insertPicCost(wb, sheet, info2.getPic9(), 3, 157, 15, 167);
        insertPicCost(wb, sheet, info2.getPic10(), 18, 157, 30, 167);
        return wb;
    }

    @Override
    public List<VeiReportInfo> getReport1ByStatus(int status) {
        return veiReportInfoMapper.selectReportInfoByStatus(status);
    }

    @Override
    public List<VeiReportInfo2> getReport2ByStatus(int status) {
        return veiReportInfo2Mapper.selectReportInfoByStatus(status);
    }

    @Override
    public int modifyPrintTime(Integer rid) {
        return reportVerifyInfoMapper.updatePrintTime(rid);
    }

    @Override
    public int modifyPrintTime2(Integer rid) {
        return reportVerifyInfo2Mapper.updatePrintTime(rid);
    }

    @Override
    public int archiveReport1() {
        return reportVerifyInfoMapper.updateStatusByPT();
    }

    @Override
    public int archiveReport2() {
        return reportVerifyInfo2Mapper.updateStatusByPT();
    }

    @Override
    public boolean checkReport2NumberRepetition(String reportNumber) {
        List<VeiReportInfoDTO2> list = veiReportInfo2Mapper.selectByReportNumber(reportNumber);
        if (null == list) {
            return false;
        } else if (list.size() >= 1) {
            return true;
        }
        return false;
    }

    /**
     * @param id
     * @param token 报告编号数字位
     * @return
     */
    @Override
    public VeiReportInfo getVeiReportInfoByRidAndToken(Integer id, String token) {
        return veiReportInfoMapper.selectByIdAndToken(id, token);
    }

    @Override
    public VeiReportInfo2 getVeiReportInfo2ByRidAndToken(Integer id, String token) {
        return veiReportInfo2Mapper.selectByIdAndToken(id, token);
    }

    @Override
    public VeiReportInfo getReportByUUId(String uuid) {
        return veiReportInfoMapper.selectByUUId(uuid);
    }

    @Override
    public int modifyAndroidReportImage(VeiReportInfo info, VehicleImage vi) {
        if (encapsulation(vi, info) == 1) {
            return veiReportInfoMapper.updateByPrimaryKeySelective(info);
        } else {
            return 0;
        }
    }

    @Override
    public ReportVerifyInfo getVeiReportStatusByRid(Integer rid) {
        return reportVerifyInfoMapper.selectByRid(rid);
    }

    @Override
    public ReportVerifyInfo2 getVeiReport2StatusByRid(Integer rid) {
        return reportVerifyInfo2Mapper.selectByRid(rid);
    }

    @Override
    public int modifyReportImage(VeiReportInfo info, VehicleImage vi) {
        if (encapsulationReport(vi, info) == 1) {
            return veiReportInfoMapper.updateByPrimaryKeySelective(info);
        } else {
            return 0;
        }
    }

    @Override
    public VeiReportInfo2 getReport2ByUUId(String uuid) {
        return veiReportInfo2Mapper.selectByUUid(uuid);
    }

    @Override
    public int modifyReport2Image(VeiReportInfo2 info, VehicleImage vi) {
        if (encapsulationReport2(vi, info) == 1) {
            return veiReportInfo2Mapper.updateByPrimaryKeySelective(info);
        } else {
            return 0;
        }
    }

    @Override
    public List<VeiReportInfoDTO2> hedaGetReport(Integer uid, Integer uid2, Integer uid3) {
        List<VeiReportInfoDTO2> list = veiReportInfo2Mapper.selectByMutiUid(uid, uid2, uid3);
        return list;
    }

    @Override
    public XSSFWorkbook exportYsjlReportExcel(VeiReportInfo info, HttpServletResponse response) {
        XSSFWorkbook wb = null;
        try {
            wb = new XSSFWorkbook(new FileInputStream(Constants.REPORT_YSJL2_URL));
        } catch (IOException e) {
            e.printStackTrace();
        }
        XSSFSheet sheet = wb.getSheetAt(0);
        sheet.getRow(1).getCell(4).setCellValue(info.getReportNumber());
        sheet.getRow(1).getCell(12).setCellValue(info.getCheckDate());

        sheet.getRow(2).getCell(12).setCellValue(info.getCheckMethod());

        sheet.getRow(5).getCell(4).setCellValue(info.getAgentName());
        sheet.getRow(5).getCell(12).setCellValue(info.getAgentPhone());

        sheet.getRow(6).getCell(4).setCellValue(info.getAgentAddress());

        sheet.getRow(7).getCell(4).setCellValue(info.getCheckPlace());

        sheet.getRow(9).getCell(4).setCellValue(info.getEquipmentManufacturer());
        sheet.getRow(10).getCell(4).setCellValue(info.getEngineManufacturerName());

        sheet.getRow(11).getCell(4).setCellValue(info.getMachineProtectionNumber());
        sheet.getRow(11).getCell(12).setCellValue(info.getEquipmentNumber());

        sheet.getRow(12).getCell(4).setCellValue(info.getMachineName());
        sheet.getRow(12).getCell(12).setCellValue(info.getTrademark());

        sheet.getRow(13).getCell(4).setCellValue(info.getMachineNumber());
        sheet.getRow(13).getCell(12).setCellValue(info.getProductionDate());

        sheet.getRow(14).getCell(4).setCellValue(info.getEquipmentColor());
        sheet.getRow(14).getCell(12).setCellValue(info.getEmissionWarranty());

        sheet.getRow(15).getCell(12).setCellValue(info.getCheckMethod());

        sheet.getRow(16).getCell(4).setCellValue(info.getMachineVin());
        sheet.getRow(16).getCell(12).setCellValue(info.getEngineNumber());

        sheet.getRow(17).getCell(4).setCellValue(info.getEmissionPeriod());
        sheet.getRow(17).getCell(12).setCellValue(info.getEngineModel());

        sheet.getRow(18).getCell(4).setCellValue(info.getEngineYear());
        sheet.getRow(18).getCell(12).setCellValue(info.getEnginePower());

        sheet.getRow(19).getCell(4).setCellValue(info.getEngineOils());
        sheet.getRow(19).getCell(12).setCellValue(info.getEngineSpeed());

//        sheet.getRow(19).getCell(4).setCellValue(info.getProtectionNumber());
//        sheet.getRow(19).getCell(12).setCellValue(info.getEngineTypeApprovalNumber());

        sheet.getRow(20).getCell(4).setCellValue(info.getMachineType());
        sheet.getRow(20).getCell(12).setCellValue(info.getCheckType());

        sheet.getRow(21).getCell(4).setCellValue(info.getWorkCharacteristic());
        sheet.getRow(21).getCell(12).setCellValue(info.getEngineAftertreatmentSystem());

        sheet.getRow(22).getCell(4).setCellValue(info.getBanBlowdownRegion());
        sheet.getRow(22).getCell(12).setCellValue(info.getDriverAlarmSystem());

        sheet.getRow(23).getCell(4).setCellValue(info.getRemoteMonitorSystem());
        sheet.getRow(23).getCell(12).setCellValue(info.getSatellitePositionSystem());

        sheet.getRow(24).getCell(4).setCellValue(info.getDriverPerformanceRestrictionSystem());
        sheet.getRow(24).getCell(12).setCellValue(info.getEcuInfo());

        sheet.getRow(26).getCell(4).setCellValue(info.getAmbientTemperature());
        sheet.getRow(26).getCell(13).setCellValue(info.getAltitude());

        sheet.getRow(27).getCell(4).setCellValue(info.getAmbientHumidity());
        sheet.getRow(27).getCell(13).setCellValue(info.getAtmosphericPressure());

        sheet.getRow(30).getCell(4).setCellValue(info.getAmbientHumidity());
        sheet.getRow(30).getCell(7).setCellValue(info.getEquipmentFactoryNumber());
        sheet.getRow(30).getCell(11).setCellValue(info.getEquipmentMeasurementCertificate());

        sheet.getRow(32).getCell(4).setCellValue(info.getCheckStartTime());
        sheet.getRow(32).getCell(10).setCellValue(info.getCheckEndTime());
        sheet.getRow(32).getCell(15).setCellValue(info.getCheckPlace());

        sheet.getRow(34).getCell(14).setCellValue(info.getAccelerateResult());
        sheet.getRow(34).getCell(16).setCellValue(info.getCheckEngineSpeed());

        sheet.getRow(35).getCell(3).setCellValue(info.getCheckResult1());
        sheet.getRow(35).getCell(6).setCellValue(info.getCheckResult2());
        sheet.getRow(35).getCell(9).setCellValue(info.getCheckResult3());

        sheet.getRow(36).getCell(3).setCellValue(info.getEmissionLimits());
        sheet.getRow(37).getCell(3).setCellValue(info.getResultJudgment());
        sheet.getRow(38).getCell(3).setCellValue(info.getVisualPlume());
        return wb;
    }

    @Override
    public List<VeiReportInfo> getReportByUId(Integer uid) {
        return veiReportInfoMapper.selectReportByUId(uid);
    }


    private int encapsulationReport2(VehicleImage vi, VeiReportInfo2 info) {
        switch (vi.getFilename()) {
            case "F_PIC1":
                info.setPic1(vi.getFileData());
                break;
            case "F_PIC2":
                info.setPic2(vi.getFileData());
                break;
            case "F_PIC3":
                info.setPic3(vi.getFileData());
                break;
            case "F_PIC4":
                info.setPic4(vi.getFileData());
                break;
            case "F_PIC5":
                info.setPic5(vi.getFileData());
                break;
            case "F_PIC6":
                info.setPic6(vi.getFileData());
                break;
            case "F_PIC7":
                info.setPic7(vi.getFileData());
                break;
            case "F_PIC8":
                info.setPic8(vi.getFileData());
                break;
            case "F_PIC9":
                info.setPic9(vi.getFileData());
                break;
            case "F_PIC10":
                info.setPic10(vi.getFileData());
                break;
            default:
                return 0;
        }
        return 1;
    }

    private int encapsulationReport(VehicleImage vi, VeiReportInfo info) {
        switch (vi.getFilename()) {
            case "F_PIC1":
                info.setFpic1(vi.getFileData());
                break;
            case "F_PIC2":
                info.setFpic2(vi.getFileData());
                break;
            case "F_PIC3":
                info.setFpic3(vi.getFileData());
                break;
            case "F_PIC4":
                info.setFpic4(vi.getFileData());
                break;
            case "F_PIC5":
                info.setFpic5(vi.getFileData());
                break;
            case "F_PIC6":
                info.setFpic6(vi.getFileData());
                break;
            case "F_PIC7":
                info.setFpic7(vi.getFileData());
                break;
            case "F_PIC8":
                info.setFpic8(vi.getFileData());
                break;
            case "F_PIC9":
                info.setFpic9(vi.getFileData());
                break;
            case "F_PIC10":
                info.setFpic10(vi.getFileData());
                break;
            default:
                return 0;
        }
        return 1;
    }

    @Override
    public XSSFWorkbook exportReportExcel(VeiReportInfo info) {
        XSSFWorkbook wb = null;
        try {
            wb = new XSSFWorkbook(new FileInputStream(Constants.REPORT_MODAL_URL));
        } catch (IOException e) {
            e.printStackTrace();
        }
        XSSFSheet sheet = wb.getSheetAt(0);
        sheet.getRow(3).getCell(3).setCellValue(info.getReportNumber());
        sheet.getRow(3).getCell(11).setCellValue(info.getCheckDate());
        sheet.getRow(4).getCell(3).setCellValue(info.getBasisStandard());
        sheet.getRow(4).getCell(11).setCellValue(info.getCheckMethod());
        sheet.getRow(5).getCell(3).setCellValue(info.getCheckOrganization());
        sheet.getRow(5).getCell(11).setCellValue(info.getOrganizationAddress());
        sheet.getRow(7).getCell(3).setCellValue(info.getAgentName());
        sheet.getRow(7).getCell(11).setCellValue(info.getAgentPhone());
        sheet.getRow(8).getCell(3).setCellValue(info.getAgentAddress());
        sheet.getRow(10).getCell(3).setCellValue(info.getEquipmentManufacturer());
        sheet.getRow(11).getCell(3).setCellValue(info.getEngineManufacturerName());
        sheet.getRow(12).getCell(3).setCellValue(info.getSerialNumber());   //序列号
        sheet.getRow(12).getCell(11).setCellValue(info.getHbNumber());   //环保编号
        sheet.getRow(13).getCell(3).setCellValue(info.getMachineProtectionNumber());
        sheet.getRow(13).getCell(11).setCellValue(info.getEquipmentNumber());
        sheet.getRow(14).getCell(3).setCellValue(info.getMachineName());
        sheet.getRow(14).getCell(11).setCellValue(info.getTrademark());
        sheet.getRow(15).getCell(3).setCellValue(info.getMachineNumber());
        sheet.getRow(15).getCell(11).setCellValue(info.getProductionDate());
        sheet.getRow(16).getCell(3).setCellValue(info.getEquipmentColor());
        sheet.getRow(16).getCell(11).setCellValue(info.getEmissionWarranty());
        sheet.getRow(17).getCell(3).setCellValue(info.getCheckBasis());
        sheet.getRow(17).getCell(11).setCellValue(info.getCheckMethod());
        sheet.getRow(18).getCell(3).setCellValue(info.getMachineVin());
        sheet.getRow(18).getCell(11).setCellValue(info.getEngineNumber());
        sheet.getRow(19).getCell(3).setCellValue(info.getEmissionPeriod());
        sheet.getRow(19).getCell(11).setCellValue(info.getEngineModel());
        sheet.getRow(20).getCell(3).setCellValue(info.getEngineYear());
        sheet.getRow(20).getCell(11).setCellValue(info.getEnginePower());
        sheet.getRow(21).getCell(3).setCellValue(info.getEngineOils());
        sheet.getRow(21).getCell(11).setCellValue(info.getEngineSpeed());
        sheet.getRow(22).getCell(3).setCellValue(info.getProtectionNumber());
        sheet.getRow(22).getCell(11).setCellValue(info.getEngineTypeApprovalNumber());
        sheet.getRow(23).getCell(3).setCellValue(info.getMachineType());
        sheet.getRow(23).getCell(11).setCellValue(info.getCheckType());
        sheet.getRow(24).getCell(3).setCellValue(info.getWorkCharacteristic());
        sheet.getRow(24).getCell(11).setCellValue(info.getEngineAftertreatmentSystem());
        sheet.getRow(25).getCell(3).setCellValue(info.getBanBlowdownRegion());
        sheet.getRow(25).getCell(11).setCellValue(info.getDriverAlarmSystem());
        sheet.getRow(26).getCell(3).setCellValue(info.getDriverPerformanceRestrictionSystem());
        sheet.getRow(26).getCell(11).setCellValue(info.getEcuInfo());
        sheet.getRow(27).getCell(3).setCellValue(info.getRemoteMonitorSystem());
        sheet.getRow(27).getCell(11).setCellValue(info.getSatellitePositionSystem());
        sheet.getRow(29).getCell(3).setCellValue(info.getAmbientTemperature());
        sheet.getRow(29).getCell(12).setCellValue(info.getAltitude());
        sheet.getRow(30).getCell(3).setCellValue(info.getAmbientHumidity());
        sheet.getRow(30).getCell(12).setCellValue(info.getAtmosphericPressure());
        sheet.getRow(33).getCell(3).setCellValue(info.getEquipmentModel());
        sheet.getRow(33).getCell(6).setCellValue(info.getEquipmentFactoryNumber());
        sheet.getRow(33).getCell(10).setCellValue(info.getEquipmentMeasurementCertificate());
        sheet.getRow(37).getCell(3).setCellValue(info.getCheckStartTime());
        sheet.getRow(37).getCell(8).setCellValue(info.getCheckEndTime());
        sheet.getRow(37).getCell(12).setCellValue(info.getCheckPlace());
        sheet.getRow(39).getCell(3).setCellValue(info.getCheckResult1());
        sheet.getRow(39).getCell(5).setCellValue(info.getCheckResult2());
        sheet.getRow(39).getCell(8).setCellValue(info.getCheckResult3());
        sheet.getRow(39).getCell(10).setCellValue(info.getCheckEngineSpeed());
        sheet.getRow(39).getCell(13).setCellValue(info.getVisualPlume() == 0 ? "不可见" : "可见");
        sheet.getRow(41).getCell(3).setCellValue(info.getAccelerateResult());
        sheet.getRow(42).getCell(3).setCellValue(info.getEmissionLimits());
        sheet.getRow(43).getCell(3).setCellValue(info.getResultJudgment());
        try {
            //有时候 签发后 无法生成二维码 , 就再次验证是否有此 二维码 , 如果没就再生成一次
            if (!FileUtils.isExist(Constants.QRCODE_IMG_LOCAL_URL1 + info.getReportNumber() + ".jpg")) {
                String qrCodeUrl = Constants.QRCODE_REPORT_URL1 + info.getReportId() + "&" + "token=" + info.getReportNumber().substring(6);
                QrCodeUtils.encode(qrCodeUrl, "", Constants.QRCODE_IMG_LOCAL_URL1, info.getReportNumber() + ".png", false);
            }
            insertPicCost(wb, sheet, Constants.QRCODE_IMG_LOCAL_URL1 + info.getReportNumber() + ".jpg", 15, 1, 16, 4);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //插入图片
        insertPicCost(wb, sheet, info.getFpic1(), 0, 46, 8, 55);
        insertPicCost(wb, sheet, info.getFpic2(), 9, 46, 17, 55);
        insertPicCost(wb, sheet, info.getFpic3(), 0, 56, 8, 66);
        insertPicCost(wb, sheet, info.getFpic4(), 9, 56, 17, 66);
        insertPicCost(wb, sheet, info.getFpic5(), 0, 67, 8, 75);
        insertPicCost(wb, sheet, info.getFpic6(), 9, 67, 17, 75);
        insertPicCost(wb, sheet, info.getFpic7(), 0, 76, 8, 85);
        insertPicCost(wb, sheet, info.getFpic8(), 9, 76, 17, 85);
        insertPicCost(wb, sheet, info.getFpic9(), 0, 86, 8, 95);
        insertPicCost(wb, sheet, info.getFpic10(), 9, 86, 17, 95);
        //生成excel文件
//        FileOutputStream out = null;
//        try {
//            out = new FileOutputStream(info.getReportNumber()+".xlsx");
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
//        try {
//            wb.write(out);
//            out.flush();
//            out.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        return wb;
    }

    private int encapsulation(VehicleImage vi, VeiReportInfo info) {
        switch (vi.getFilename()) {
            case "F_PIC1":
                info.setFpic7(vi.getFileData());
                break;
            case "F_PIC2":
                info.setFpic4(vi.getFileData());
                break;
            case "F_PIC3":
                info.setFpic2(vi.getFileData());
                break;
            case "F_PIC4":
                info.setFpic3(vi.getFileData());
                break;
            case "F_PIC5":
                info.setFpic1(vi.getFileData());
                break;
            case "F_PIC6":
                info.setFpic10(vi.getFileData());
                break;
            case "F_PIC7":
                info.setFpic9(vi.getFileData());
                break;
            case "F_PIC8":
                info.setFpic5(vi.getFileData());
                break;
            case "F_PIC9":
                info.setFpic8(vi.getFileData());
                break;
            case "F_FRZSYYZZ":
//                info.setFpic9(vi.getFileData());
                break;
            case "F_ET_PIC1":
                info.setFpic6(vi.getFileData());
            default:
                return 0;
        }
        return 1;
    }

    public static void insertPicCost(XSSFWorkbook workBook, XSSFSheet topPic, String pic
            , int x1, int x2, int y1, int y2) {
        if (StringUtils.isEmpty(pic)) {
            return;
        } else {
            if (!pic.contains(Constants.REPORT_IMG_LOCAL_URL)) {
                pic = Constants.REPORT_IMG_LOCAL_URL + pic;
            }
        }
        try {
            File file = new File(pic);
            FileInputStream fin = new FileInputStream(file);
            byte[] bytes  = new byte[fin.available()];
            int read = fin.read(bytes);   //不等于-1 即可
            Drawing patriarch = topPic.createDrawingPatriarch();
            //图片一导出到单元格B2中
            XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0,
                    (short) x1, x2, (short) y1, y2);
            // 插入图片
            Picture picture = patriarch.createPicture(anchor, workBook.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_PNG));
            System.out.println(picture.getPictureData().getData().length);
        } catch (IOException io) {
            log.error("插入失败 : " + pic);
        }
    }
}